<?php

/**
 * Created by PhpStorm.
 * User: woddp
 * Date: 2016/8/14
 * Time: 0:41
 */
class UserForm extends \Phalcon\Forms\Form
{
    
    public function initialize(){


        //userName
        $this->add(new \Phalcon\Forms\Element\Text('userName'));
        $userName=new \Phalcon\Forms\Element\Text('userName');

        $userName->addValidators(array(
            new \Phalcon\Validation\Validator\PresenceOf(array( //必填
               'message'=>'用户名必填',
            )),
            new \Phalcon\Validation\Validator\StringLength(array( //字符串长度
                    'max' => 8,
                    'min' => 2,
                    'messageMaximum' => '最大五个字符',
                    'messageMinimum' => '最小两个字符'
            )),
            new \Phalcon\Validation\Validator\Uniqueness(array(  //唯一存在
                    'model' => 'User',
                     'message' => '用户名已经存在',
            )),
        ));
        $this->add($userName);

        //email
        $emai=new \Phalcon\Forms\Element\Text('emai');
        $emai->addValidators(array(
            new \Phalcon\Validation\Validator\PresenceOf(array(
                'message'=>"邮箱必填",
            )),
            new \Phalcon\Validation\Validator\Email(array(
                'message'=>'邮箱格式不正确'
            )),
        ));
        $this->add($emai);
        //password
        $password=new \Phalcon\Forms\Element\Text('password');
        $password->addValidators(array(
            new \Phalcon\Validation\Validator\PresenceOf(array(
                'message'=>'密码必填',
            )),
            new \Phalcon\Validation\Validator\StringLength(array(
                'min' => 4,
                'messageMinimum'=>'密码长度不能小于四位',
            )),
        ));
        $this->add($password);
        //repassword
        $repassword=new \Phalcon\Forms\Element\Text('repassword');
        $repassword->addValidators(array(
            new \Phalcon\Validation\Validator\PresenceOf(array(
                'message'=>'重复密码必填',
            )),
            new \Phalcon\Validation\Validator\StringLength(array(
                'min' => 4,
                'messageMinimum'=>'密码长度不能小于四位',
            )),
            new \Phalcon\Validation\Validator\Confirmation(array(
              'with' => 'password',
              'message'=>'两次密码不一致',
            )),
        ));
        $this->add($repassword);


    }

}